Apache Wink : 7 Apache Wink Representations
This page last changed on Oct 14, 2009 by michael.
Apache Wink RepresentationsIn addition to the JAX-RS standard representations Apache Wink provides an expanded set of representations that can be used by an application to expose resources in a rich set of representations. The following section provides information about the representations that are supported by Apache Wink.
Apache Wink Representations Request FlowThe following diagram illustrates the client request flow for a resource. A resource is an abstract entity and as such can not be transmitted between peers. When a client is required to send or receive a resource it must use a representation of that resource. The resource representation is a specific formatting of the resource data. The diagram illustrates that a request for a resource is in fact a request for a specific representation of that resource. Apache Wink implements resource representations through the use of providers for java objects as defined by the JAX-RS specification. Apache Wink ProvidersIn addition to JAX-RS standard providers (refer to section 4.2 of the JAX-RS specification), Apache Wink provides a set of complementary providers. The purpose of these providers is to provide mapping services between various representations for example Atom, APP, OpenSearch, CSV, JSON and HTML, and their associated Java data models. The Apache Wink providers are pre-registered and delivered with the Apache Wink runtime along with the JAX-RS standard providers. Apache Wink provides an additional method for defining the life cycle of a provider via the use of the @Scope annotation and a way to define the providers priorities. ScopingThe JAX-RS specification defines by default, that a singleton instance of each provider class is instantiated for each JAX-RS application. Apache Wink fully supports this requirement and in addition provides a "Prototype" lifecycle, which is an instance per-request lifecycle. Prototype ExampleThe following example shows how to define a provider with a prototype lifecycle. @Scope(ScopeType.PROTOTYPE)
@Provider
public class MyProvider implements MessageBodyReader<String>{
...
}
Singleton Example 1The following example shows how to define a provider with a singleton lifecycle. @Scope(ScopeType.SINGELTON)
@Provider
public class MyProvider implements MessageBodyReader<String>{
...
}
Singleton Example 2The following example shows that when the @Scope annotation is not used, the provider will be a singleton, as per the JAX-RS specification. @Provider
public class MyProvider implements MessageBodyReader<String>{
...
}
PriorityApache Wink provides a method for setting a priority for a provider.
Apache Wink Representations Diagram.jpg (image/jpeg)
Apache Wink Representations Diagram2.jpg (image/jpeg) |
Document generated by Confluence on Nov 11, 2009 06:57 |